package com.example.note.viewmodel;

import android.app.Application;

import androidx.annotation.NonNull;
import androidx.lifecycle.AndroidViewModel;
import androidx.lifecycle.LiveData;

import com.example.note.database.DiaryEntity;
import com.example.note.repository.DiaryRepository;

import java.util.List;

public class DiaryViewModel extends AndroidViewModel {
    
    private DiaryRepository repository;
    private LiveData<List<DiaryEntity>> allDiaries;
    
    public DiaryViewModel(@NonNull Application application) {
        super(application);
        repository = new DiaryRepository(application);
        allDiaries = repository.getAllDiaries();
    }
    
    public LiveData<List<DiaryEntity>> getAllDiaries() {
        return allDiaries;
    }
    
    public LiveData<DiaryEntity> getDiaryById(int id) {
        return repository.getDiaryById(id);
    }
    
    public LiveData<List<DiaryEntity>> getDiariesByDate(String date) {
        return repository.getDiariesByDate(date);
    }
    
    public LiveData<List<DiaryEntity>> searchDiaries(String keyword) {
        return repository.searchDiaries(keyword);
    }
    
    public LiveData<List<DiaryEntity>> getHandwrittenDiaries() {
        return repository.getHandwrittenDiaries();
    }
    
    public void insert(DiaryEntity diary) {
        repository.insertDiary(diary);
    }
    
    public void update(DiaryEntity diary) {
        repository.updateDiary(diary);
    }
    
    public void delete(DiaryEntity diary) {
        repository.deleteDiary(diary);
    }
    
    public LiveData<Integer> getDiaryCount() {
        return repository.getDiaryCount();
    }
}